<?php

//8/30/2009: Immanuel192; Album New module

class albumnew_module{
	function name() { return "New Album Module";  }
	function description() { return "Uses to show album that add recently";  }
	
	function author() { return "Immanuel192"; }
	
	function hasContent() { return false; }
	function hasSources() { return false; }
	function hasViews()   { return true; }
	
	function supportsWorkflow() { return false; }
	
	function permissions($internal = "") {
		return array();
	}
	
	function show($view,$loc,$title = '') {
		global $db;
		
		$template = new template('albumnew_module',$view,$loc);		
		
		
		if (!defined('SYS_FILES')) require_once(BASE.'subsystems/files.php');
		
		$albums= $db->selectObjects('album'," is_new = 1");
		for($i=0; $i<count($albums); $i++) {
			if ($albums[$i]->image_id == 0) {
				$albums[$i]->picpath = '';
			} else {
				$file = $db->selectObject('file', 'id='.$albums[$i]->image_id);
				$albums[$i]->picpath = $file->directory.'/'.$file->filename;
			}
			
			// for rating
			$rate_1 = floor($albums[$i]->rate);
			$rate_half = $albums[$i]->rate - $rate_1;
      $rate_2 = 5- $rate_1 - (($rate_half > 0)?1:0);
      $rate=array();
      for ($j=1;$j<=$rate_1;$j++)
        $rate[$j]=1; // for active rate
      if ($rate_half > 0)
        $rate[$rate_1+1]=3; // for rate half
      for ($j=5-$rate_2+1;$j<=5;$j++)
        $rate[$j]=2; // for active rate
      $albums[$i]->rate=$rate;
			// end of rating
			
			// for format_type
		  $temp=$db->selectObject("album_format","id = ".$albums[$i]->format);
		  $albums[$i]->format_text = $temp->name;
			// end of format type
			// for genre 
      $temp=$db->selectObject("album_genre","id = ".$albums[$i]->genre);
  	  $albums[$i]->genre_text = $temp->name;
			// end of genre
			
			// count all music in this album
			$albums[$i]->musics=$db->countObjects('musics','album_id='.$albums[$i]->id);
    
		}
		$template->assign('moduletitle', $title);
		$template->assign('albums', $albums);
		$template->output();
	}
}

?>
